﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Frame.Lib.Core.Dispatch;
using Frame.Lib.Common;
using Frame.Lib.Utilities;



namespace Frame.Web.Admin.Dispatch
{
    public partial class Edit : PageEdit
    {
        private DispatchBO Dispatch
        {
            get
            {
                return DispatchBO.Instance<DispatchBO>();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<EnumInfo> list = ConvertUtil.ConvertEnum(typeof(DispatchState));
                drpState.DataSource = list;
                drpState.DataTextField = "Name";
                drpState.DataValueField = "ID";
                drpState.DataBind();

                DispInfo();
            }
        }

        private void DispInfo()
        {
            if (!string.IsNullOrEmpty(this.PKID))
            {
                DispatchInfo info = this.Dispatch.GetInfo(this.PKID);

                this.Name.Text = info.Name;
                this.Interval.Text = info.Interval.ToString();


            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            DispatchInfo info = this.Dispatch.GetInfo(this.PKID);
            info.Name = this.Name.Text;
            info.Interval = int.Parse(this.Interval.Text);
            info.State = int.Parse(drpState.SelectedValue);

            this.Dispatch.Save(info);

            JSUtil.RefreshView();
        }
    }
}